//
// Created by Lenovo on 2020/8/27.
//
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1e5+10;
int a[maxn];
int tmp[maxn];
int merg(int l,int mid,int r)
{
    for(int i = l;i<=r;i++) tmp[i] = a[i];
    int ans = 0;
    int i = l,j=mid+1;
    for(int k = l;k<=r;k++)
    {
        if(i>mid)
        {
            a[k] = tmp[j];
            j++;
        }
        else if(j>r)
        {
            a[k] = tmp[i];
            i++;
        }
        else if(tmp[i]<tmp[j])
        {
            a[k] = tmp[i];
            i++;
        }
        else
        {
            a[k] = tmp[j];
            j++;
            ans += (mid-i+1);
        }

    }
    return ans;
}
int mergsort(int l,int r)
{
    if(l>=r) return 0;
    int mid = (l+r)>>1;
    int left = mergsort(l,mid);
    int right = mergsort(mid+1,r);
    int ans =  (left+right+merg(l,mid,r));
   // printf("%d %d*****%d\n",l,r,ans);
    return ans;
}

int main()
{
    int n;
    while(scanf("%d",&n)!=EOF&&n)
    {
        for(int i = 1;i<=n;i++) scanf("%d",&a[i]);
        int ans =  mergsort(1,n);
        printf("%d\n",ans);
    }


}

